package cn.foolishbird.crow.mybatis.plus.handlers;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;

/**
 * @author foolish bird
 */
public abstract class AbstractMetaObjectHandler implements MetaObjectHandler {

	public AbstractMetaObjectHandler() {
	}

	@Override
	public void insertFill(MetaObject metaObject) {
		if (objectNeedInsertFill(metaObject)) {
			doInsertFill(metaObject);
		}
	}

	@Override
	public void updateFill(MetaObject metaObject) {
		if (objectNeedUpdateFill(metaObject)) {
			doUpdateFill(metaObject);
		}
	}

	/**
	 * 实例是否需要填充
	 *
	 * @param metaObject
	 * @return
	 */
	protected abstract boolean objectNeedInsertFill(MetaObject metaObject);

	/**
	 * 实例是否需要填充
	 *
	 * @param metaObject
	 * @return
	 */
	protected abstract boolean objectNeedUpdateFill(MetaObject metaObject);


	/**
	 * insert填充项目
	 *
	 * @param metaObject
	 */
	protected abstract void doInsertFill(MetaObject metaObject);

	/**
	 * update填充项目
	 *
	 * @param metaObject
	 */
	protected abstract void doUpdateFill(MetaObject metaObject);
}
